import requests


class SendMethod:
    # 发送请求方法
    @staticmethod
    def send_method(method, url, params=None, headers=None, data=None, json=None):
        if method in ["get", "post"]:
            resp = requests.request(method=method, url=url, params=params, headers=headers, data=data, json=json)
        else:
            resp = None
            print('请求方法错误')

        result = {}
        if resp is not None:
            result["status_code"] = resp.status_code
            result["headers"] = resp.headers
            result["json"] = resp.json()
            result["resp_time"] = int(resp.elapsed.microseconds / 1000)
            return result
        else:
            return resp


# if __name__ == '__main__':
#     url = "http://47.108.206.100:8080/admin/login"
#     method = "post"
#     body = {
#         "username": "admin",
#         "password": "macro123"
#     }
#     print(SendMethod.send_method(method=method, url=url, json=body))
